#!/usr/bin/env python
#coding:utf-8
#利用SGMLParser抓取新华网MMS

import urllib
import sys
from sgmllib import SGMLParser

class URLLister(SGMLParser):
    def reset(self):
        SGMLParser.reset(self)
        self.urls = []

    def start_param(self, attrs):
        value = [v for k, v in attrs if k == 'value']
        if value:
            if str(value).startswith("['mms']"):
                self.urls.extend(value)

class Links():
    def getLinks(self, uri):
        usock = urllib.urlopen(uri)
        parse = URLLister()
        parse.feed(usock.read())
        usock.close()
        print 'MMS Found:'
        for url in parse.urls:
            print url

def main():
    try:
        links = Links()
        sys.stdout.write('输入URL:')
        uri = raw_input()
        links.getLinks(uri)
    except IOError:
        sys.stdout.write('IOError,未知位置:'+uri+'\n')

if __name__ == '__main__':
    main()
